package com.DataFactory.TaskManagement.controller;

import com.DataFactory.TaskManagement.common.result.PageResult;
import com.DataFactory.TaskManagement.common.result.Result;
import com.DataFactory.TaskManagement.model.form.TaskForm;
import com.DataFactory.TaskManagement.model.query.TaskQuery;
import com.DataFactory.TaskManagement.model.vo.TaskPageVO;
import com.DataFactory.TaskManagement.service.TaskService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author shumm
 * @Description
 * @since 2024-03-28 21:18
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/task")
public class TaskController {

    private final TaskService taskService;


    /**
     * 获取任务分页列表
     * @param queryParams
     * @return
     */
    @GetMapping("/page")
    public PageResult<TaskPageVO> getTaskPage(@ParameterObject @Valid TaskQuery queryParams){
        Page<TaskPageVO> result= taskService.getTaskPage(queryParams);
        return PageResult.success(result);
    }

    /**
     * 新增任务
     * @param form
     * @return
     */
    @PostMapping
    public Result saveTask(@RequestBody @Valid TaskForm form){
        boolean result= taskService.saveTask(form);
        return Result.judge(result);
    }
    /*
      废弃以下接口
     */
//
//    /**
//     * 更新任务
//     * @param taskId
//     * @param form
//     * @return
//     */
//    @PutMapping("/{taskId}")
//    public Result updateTask(@PathVariable Integer taskId,@RequestBody @Valid TaskForm form){
//        boolean result= taskService.updateTask(taskId,form);
//        return Result.judge(result);
//    }
//
//    /**
//     * 删除任务
//     * @param ids
//     * @return
//     */
//    @DeleteMapping("/delete/{ids}")
//    public Result deleteTask(@PathVariable String ids){
//        boolean result= taskService.deleteTasks(ids);
//        return Result.judge(result);
//    }
//
//    /**
//     * 获取任务详情
//     * @param taskId
//     * @return
//     */
//    @GetMapping("/{taskId}/form")
//    public Result<TaskForm> getTaskForm(@Parameter(description = "任务id") @PathVariable Integer taskId) {
//        TaskForm result = taskService.getTaskForm(taskId);
//        return Result.success(result);
//    }
}
